package com.example.handsets8app.Base;

import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.example.handsets8app.Utils.LogUtil;
import com.wanjian.cockroach.Cockroach;

public class BaseApplication extends Application {

    private static Context mAppContext;

    @Override
    public void onCreate() {
        super.onCreate();
        mAppContext = this;

        // 防止崩溃
        initCock();
    }

    public static Context getAppContext() {
        return mAppContext;
    }

    private void initCock() {
        Cockroach.install(new Cockroach.ExceptionHandler() {
            @Override
            public void handlerException(final Thread thread, final Throwable throwable) {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            LogUtil.d("Exception Happend\n" + thread + "\n" + throwable.toString());
                        } catch (Throwable e) {

                        }

                    }
                });
            }
        });
    }
}
